package com.example.traning.mvc;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

/**
 * /controller/hello
 * @author lei yu
 * @since 2025/04/23
 */
@Controller
@RequestMapping("/")
public class HelloController {


    @RequestMapping("/hello")
    public String hello() {
        System.out.println("hello 方法");
        // 响应
        // redirect 重定向
        // forward  转发  默认
        return "index.jsp";
    }

    @RequestMapping("/user")
    public ModelAndView user() {
        System.out.println("user 方法");
        ModelAndView mav = new ModelAndView("user"); // 指定视图名称
        mav.addObject("username", "张三");
        mav.addObject("age", 25);
        return mav;
    }
}
